package com.matrix.rabbitmqtest.topic;

import cn.hutool.core.lang.Console;
import com.matrix.rabbitmqtest.util.AppKeys;
import com.matrix.rabbitmqtest.util.RabbitMQUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;

/**
 * Topic模式
 * Producer
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtil.getChannel();
        channel.exchangeDeclare(AppKeys.TOPIC_EXCHANGE, BuiltinExchangeType.TOPIC);
        while (true){
            String input = Console.input();
            channel.basicPublish(AppKeys.TOPIC_EXCHANGE,input,null, input.getBytes(StandardCharsets.UTF_8));
        }
    }
}
